package com.liu.maven;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
 
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
 
/***
 * 使用dom4j开源项目，需要引入dom4j-1.6.1.jar和jaxen-1.1-beta-6.jar包
 *
 * @author ouxu
 *
 */
public class XmlHelper {
public void readXmlByUrl() throws Exception {
        List<Object> list;
        URL url = new URL("http://feed.cnblogs.com/blog/u/120107/rss");
        SAXReader reader = new SAXReader();
        Document document = reader.read(url);
        
        Element rootElement = document.getRootElement();
        List list_item = rootElement.elements("entry");
        
       /* if (list_item.size() > 0) {
            list = new ArrayList<Object>();
        }*/
        
        for (int i = 0; i < list_item.size(); i++) {
            Element item = (Element) list_item.get(i);
            System.out.println("id:" + item.element("id").getText());
            System.out.println("title:" + item.element("title").getText());
            System.out.println("summary:" + item.element("summary").getText());
            System.out.println("published:" + item.element("published").getText());
            System.out.println("updated:" + item.element("updated").getText());
            System.out.println("name:" + item.element("author").element("name").getText());
            System.out.println("uri:" + item.element("author").element("uri").getText());
            System.out.println("************************");
            System.out.println();
            System.out.println();
            System.out.println();
            System.out.println();
        }
 
    }
 
    public static void main(String[] args) {
        try {
            new XmlHelper().readXmlByUrl();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

